{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "pd.set_option('display.max_colwidth', -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "using Keras version: 2.2.4\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'0.6.0'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import ktrain\n",
    "ktrain.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 1:  Get Raw Document Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 20newsgroups\n",
    "from sklearn.datasets import fetch_20newsgroups\n",
    "remove = ('headers', 'footers', 'quotes')\n",
    "newsgroups_train = fetch_20newsgroups(subset='train', remove=remove)\n",
    "newsgroups_test = fetch_20newsgroups(subset='test', remove=remove)\n",
    "texts = newsgroups_train.data +  newsgroups_test.data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 2:  Represent Documents as Semantically Meaningful Vectors With LDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n_topics automatically set to 97\n",
      "preprocessing texts...\n",
      "fitting model...\n",
      "iteration: 1 of max_iter: 5\n",
      "iteration: 2 of max_iter: 5\n",
      "iteration: 3 of max_iter: 5\n",
      "iteration: 4 of max_iter: 5\n",
      "iteration: 5 of max_iter: 5\n",
      "done.\n",
      "CPU times: user 16min 17s, sys: 41min 59s, total: 58min 17s\n",
      "Wall time: 1min 56s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "tm = ktrain.text.get_topic_model(texts, n_features=10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done.\n",
      "CPU times: user 1min 26s, sys: 3min 15s, total: 4min 41s\n",
      "Wall time: 12.2 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "tm.build(texts, threshold=0.25)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 3:  Train a Document Recommender"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "tm.train_recommender()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 4: Generate Recommendations\n",
    "\n",
    "\n",
    "Given some text, recommend documents that are semantically relevant to it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "rawtext = \"\"\"\n",
    "            Elon Musk leads Space Exploration Technologies (SpaceX), where he oversees\n",
    "            the development and manufacturing of advanced rockets and spacecraft for missions\n",
    "            to and beyond Earth orbit.\n",
    "            \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RESULT #1\n",
      "TEXT:\n",
      "\tArchive-name: space/new_probes Last-modified: $Date: 93/04/01 14:39:17 $ UPCOMING PLANETARY PROBES - MISSIONS AND SCHEDULES Information on upcoming or currently active missions not mentioned below would be welcome. Sources: NASA fact sheets, Cassini Mission Design team, ISAS/NASDA launch schedules, press kits. ASUKA (ASTRO-D) - ISAS (Japan) X-ray astronomy satellite, launched into Earth orbit on 2/20/93. Equipped with large-area wide-wavelength (1-20 Angstrom) X-ray telescope, X-ray CCD cameras, and imaging gas scintillation proportional counters. CASSINI - Saturn orbiter and Titan atmosphere probe. Cassini is a joint NASA/ESA project designed to accomplish an exploration of the Saturnian system with its Cassini Saturn Orbiter and Huygens Titan Probe. Cassini is scheduled for launch aboard a Titan IV/Centaur in October of 1997. After gravity assists of Venus, Earth and Jupiter in a VVEJGA trajectory, the spacecraft will arrive at Saturn in June of 2004. Upon arrival, the Cassini spacecraft performs several maneuvers to achieve an orbit around Saturn. Near the end of this initial orbit, the Huygens Probe separates from the Orbiter and descends through the atmosphere of Titan. The Orbiter relays the Probe data to Earth for about 3 hours while the Probe enters and traverses the cloudy atmosphere to the surface. After the completion of the Probe mission, the Orbiter continues touring the Saturnian system for three and a half years. Titan synchronous orbit trajectories will allow about 35 flybys of Titan and targeted flybys of Iapetus, Dione and Enceladus. The objectives of the mission are threefold: conduct detailed studies of Saturn's atmosphere, rings and magnetosphere; conduct close-up studies of Saturn's satellites, and characterize Titan's atmosphere and surface. One of the most intriguing aspects of Titan is the possibility that its surface may be covered in part with lakes of liquid hydrocarbons that result from photochemical processes in its upper atmosphere. These hydrocarbons condense to form a global smog layer and eventually rain down onto the surface. The Cassini orbiter will use onboard radar to peer through Titan's clouds and determine if there is liquid on the surface. Experiments aboard both the orbiter and the entry probe will investigate the chemical processes that produce this unique atmosphere. The Cassini mission is named for Jean Dominique Cassini (1625-1712), the first director of the Paris Observatory, who discovered several of Saturn's satellites and the major division in its rings. The Titan atmospheric entry probe is named for the Dutch physicist Christiaan Huygens (1629-1695), who discovered Titan and first described the true nature of Saturn's rings. Key Scheduled Dates for the Cassini Mission (VVEJGA Trajectory) ------------------------------------------------------------- 10/06/97 - Titan IV/Centaur Launch 04/21/98 - Venus 1 Gravity Assist 06/20/99 - Venus 2 Gravity Assist 08/16/99 - Earth Gravity Assist 12/30/00 - Jupiter Gravity Assist 06/25/04 - Saturn Arrival 01/09/05 - Titan Probe Release 01/30/05 - Titan Probe Entry 06/25/08 - End of Primary Mission (Schedule last updated 7/22/92) GALILEO - Jupiter orbiter and atmosphere probe, in transit. Has returned the first resolved images of an asteroid, Gaspra, while in transit to Jupiter. Efforts to unfurl the stuck High-Gain\n",
      "\n",
      "RESULT #2\n",
      "TEXT:\n",
      "\tArchive-name: space/schedule Last-modified: $Date: 93/04/01 14:39:23 $ SPACE SHUTTLE ANSWERS, LAUNCH SCHEDULES, TV COVERAGE SHUTTLE LAUNCHINGS AND LANDINGS; SCHEDULES AND HOW TO SEE THEM Shuttle operations are discussed in the Usenet group sci.space.shuttle, and Ken Hollis (gandalf@pro-electric.cts.com) posts a compressed version of the shuttle manifest (launch dates and other information) periodically there. The manifest is also available from the Ames SPACE archive in SPACE/FAQ/manifest. The portion of his manifest formerly included in this FAQ has been removed; please refer to his posting or the archived copy. For the most up to date information on upcoming missions, call (407) 867-INFO (867-4636) at Kennedy Space Center. Official NASA shuttle status reports are posted to sci.space.news frequently. WHY DOES THE SHUTTLE ROLL JUST AFTER LIFTOFF? The following answer and translation are provided by Ken Jenks (kjenks@gothamcity.jsc.nasa.gov). The \"Ascent Guidance and Flight Control Training Manual,\" ASC G&C 2102, \"During the vertical rise phase, the launch pad attitude is commanded until an I-loaded V(rel) sufficient to assure launch tower clearance is achieved. Then, the tilt maneuver (roll program) orients the vehicle to a heads down attitude required to generate a negative q-alpha, which in turn alleviates structural loading. Other advantages with this attitude are performance gain, decreased abort maneuver complexity, improved S-band look angles, and crew view of the horizon. The tilt maneuver is also required to start gaining downrange velocity to achieve the main engine cutoff (MECO) target in second stage.\" This really is a good answer, but it's couched in NASA jargon. I'll try to interpret. 1) We wait until the Shuttle clears the tower before rolling. 2) Then, we roll the Shuttle around so that the angle of attack between the wind caused by passage through the atmosphere (the \"relative wind\") and the chord of the wings (the imaginary line between the leading edge and the trailing edge) is a slightly negative angle (\"a negative q-alpha\"). This causes a little bit of \"downward\" force (toward the belly of the Orbiter, or the +Z direction) and this force \"alleviates structural loading.\" We have to be careful about those wings -- they're about the most \"delicate\" part of the vehicle. 3) The new attitude (after the roll) also allows us to carry more mass to orbit, or to achieve a higher orbit with the same mass, or to change the orbit to a higher or lower inclination than would be the case if we didn't roll (\"performance gain\"). 4) The new attitude allows the crew to fly a less complicated flight path if they had to execute one of the more dangerous abort maneuvers, the Return To Launch Site (\"decreased abort maneuver complexity\"). 5) The new attitude improves the ability for ground-based radio antennae to have a good line-of-sight signal with the S-band radio antennae on the Orbiter (\"improved S-band look angles\"). 6) The new attitude allows the crew to see the horizon, which is a helpful (but not mandatory) part of piloting any flying machine. 7) The new attitude orients the Shuttle so\n",
      "\n",
      "RESULT #3\n",
      "TEXT:\n",
      "\tAll of this talk about a COMMERCIAL space race (i.e. $1G to the first 1-year moon base) is intriguing. Similar prizes have influenced aerospace development before. The $25k Orteig prize helped Lindbergh sell his Spirit of Saint Louis venture to his financial backers. If memory serves, the $25k prize would not have been enough to totally reimburse some of the more expensive transatlantic projects (such as Fokker's, Nungesser and other multi-engine projects). However Lindbergh ultimately kept his total costs below that amount. But I strongly suspect that his Saint Louis backers had the foresight to realize that much more was at stake than $25,000. Could it work with the moon? Who are the far-sighted financial backers of today?\n",
      "\n",
      "RESULT #4\n",
      "TEXT:\n",
      "\tFrom the article \"What's New\" Apr-16-93 in sci.physics.research: ........ WHAT'S NEW (in my opinion), Friday, 16 April 1993 Washington, DC 1. SPACE BILLBOARDS! IS THIS ONE THE \"SPINOFFS\" WE WERE PROMISED? In 1950, science fiction writer Robert Heinlein published \"The Man Who Sold the Moon,\" which involved a dispute over the sale of rights to the Moon for use as billboard. NASA has taken the firsteps toward this hideous vision of the future. Observers were startled this spring when a NASA launch vehicle arrived at the pad with \"SCHWARZENEGGER\" painted in huge block letters on the side of the booster rockets. Space Marketing Inc. had arranged for the ad to promote Arnold's latest movie. Now, Space Marketing is working with University of Colorado and Livermore engineers on a plan to place a mile-long inflatable billboard in low-earth orbit. NASA would provide contractual launch services. However, since NASA bases its charge on seriously flawed cost estimates (WN 26 Mar 93) the taxpayers would bear most of the expense. This may look like environmental vandalism, but Mike Lawson, CEO of Space Marketing, told us yesterday that the real purpose of the project is to help the environment! The platform will carry ozone monitors he explained--advertising is just to help defray costs. .......... What do you think of this revolting and hideous attempt to vandalize the night sky? It is not even April 1 anymore. What about light pollution in observations? (I read somewhere else that it might even be visible during the day, leave alone at night). Is NASA really supporting this junk? Are protesting groups being organized in the States? Really, really depressed. Enzo\n",
      "\n",
      "RESULT #5\n",
      "TEXT:\n",
      "\tWhat evidence indicates that Gamma Ray bursters are very far away? Their distribution is very isotropic and the intensity distribution, crudely speaking, indicates we're seeing an edge to the distribution. Given the enormous power, i was just wondering, what if they are quantum black holes or something like that fairly close by? Why would they have to be at galactic ranges? Now, in the good old days before GRO data, it was thought the gamma bursters were neutron stars in the galaxy, it was expected that GRO would confirm this by either showing they were a local population (within a few hundred light years) or that they were in the galactic halo. (Mechanism was not known but several plausible ones existed) (also to be fair it was noted that the _brightest_ burster was probably in the LMC, suggesting theorists might be wrong back then...) As the Sun is not at the center of the galaxy a halo population should show anisotropy (a local disk population is ruled out completely at this stage) - to avoid the anisotropy you have to push the halo out, the energy then gets large, the mechanism of getting NS out that far becomes questionable, and we should start to see for example the Andromeda's bursters. The data is consistent with either a Oort cloud distribution (but only just) - but no one can think of a plausible source with the right spectrum. Or, it can be a cosmological distances (hence isotropy) and the edge is \"the edge of the Universe\" ;-) If at cosmological distances you need very high energy (to detect) and a very compact source (for spectrum), ergo a neutron star colliding with another neutron star or black hole. Even then getting the spectrum is very hard, but conceivable. If we know anything about physics at that level, the bursters are not due to quantum black holes or cosmic strings, wrong spectrum for one thing. The situation is further complicated by recent claims that there are two classes of sources ;-) [in the colliding NS they'd actually probably fit relatively easily into the NS-NS and NS-BH collision scenarios respectively] my own pet theory is that it's Flying saucers entering hyperspace :-) but the reason i am asking is that most everyone assumes that they are colliding nuetron stars or spinning black holes, i just wondered if any mechanism could exist and place them closer in. If you can think of one, remember to invite me to Stockholm...\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, doc in enumerate(tm.recommend(text=rawtext, n=5)):\n",
    "    print('RESULT #%s'% (i+1))\n",
    "    print('TEXT:\\n\\t%s' % (\" \".join(doc[0].split()[:500])))\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Saving and Restoring the Topic Model\n",
    "\n",
    "The topic model can be saved and restored as follows.\n",
    "\n",
    "**Save the Topic Model:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "tm.save('/tmp/tm')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Restore the Topic Model and Rebuild the Document-Topic Matrix**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done.\n"
     ]
    }
   ],
   "source": [
    "tm = ktrain.text.load_topic_model('/tmp/tm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done.\n"
     ]
    }
   ],
   "source": [
    "tm.build(texts, threshold=0.25)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the scorer and recommender are not saved, only the LDA topic model is saved.  So, the scorer and recommender should be retrained prior to use as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "tm.train_recommender()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "rawtext = \"\"\"\n",
    "            Elon Musk leads Space Exploration Technologies (SpaceX), where he oversees\n",
    "            the development and manufacturing of advanced rockets and spacecraft for missions\n",
    "            to and beyond Earth orbit.\n",
    "            \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Archive-name: space/new_probes\n",
      "Last-modified: $Date: 93/04/01 14:39:17 $\n",
      "\n",
      "UPCOMING PLANETARY PROBES - MISSIONS AND SCHEDULES\n",
      "\n",
      "    Information on upcoming or currently active missions not mentioned below\n",
      "    would be welcome. Sources: NASA fact sheets, Cassini Mission Design\n",
      "    team, ISAS/NASDA launch schedules, press kits.\n",
      "\n",
      "\n",
      "    ASUKA (ASTRO-D) - ISAS (Japan) X-ray astronomy satellite, launched into\n",
      "    Earth orbit on 2/20/93. Equipped with large-area wide-wavelength (1-20\n",
      "    Angstrom) X-ray telescope, X-ray CCD cameras, and imaging gas\n",
      "    scintillation proportional counters.\n",
      "\n",
      "\n",
      "    CASSINI - Saturn orbiter and Titan atmosphere probe. Cassini is a joint\n",
      "    NASA/ESA project designed to accomplish an exploration of the Saturnian\n",
      "    system with its Cassini Saturn Orbiter and Huygens Titan Probe. Cassini\n",
      "    is scheduled for launch aboard a Titan IV/Centaur in October of 1997.\n",
      "    After gravity assists of Venus, Earth and Jupiter in a VVEJGA\n",
      "    trajectory, the spacecraft will arrive at Saturn in June of 2004. Upon\n",
      "    arrival, the Cassini spacecraft performs several maneuvers to achieve an\n",
      "    orbit around Saturn. Near the end of this initial orbit, the Huygens\n",
      "    Probe separates from the Orbiter and descends through the atmosphere of\n",
      "    Titan. The Orbiter relays the Probe data to Earth for about 3 hours\n",
      "    while the Probe enters and traverses the cloudy atmosphere to the\n",
      "    surface. After the completion of the Probe mission, the Orbiter\n",
      "    continues touring the Saturnian system for three and a half years. Titan\n",
      "    synchronous orbit trajectories will allow about 35 flybys of Titan and\n",
      "    targeted flybys of Iapetus, Dione and Enceladus. The objectives of the\n",
      "    mission are threefold: conduct detailed studies of Saturn's atmosphere,\n",
      "    rings and magnetosphere; conduct close-up studies of Saturn's\n",
      "    satellites, and characterize Titan's atmosphere and surface.\n",
      "\n",
      "    One of the most intriguing aspects of Titan is the possibility that its\n",
      "    surface may be covered in part with lakes of liquid hydrocarbons that\n",
      "    result from photochemical processes in its upper atmosphere. These\n",
      "    hydrocarbons condense to form a global smog layer and eventually rain\n",
      "    down onto the surface. The Cassini orbiter will use onboard radar to\n",
      "    peer through Titan's clouds and determine if there is liquid on the\n",
      "    surface. Experiments aboard both the orbiter and the entry probe will\n",
      "    investigate the chemical processes that produce this unique atmosphere.\n",
      "\n",
      "    The Cassini mission is named for Jean Dominique Cassini (1625-1712), the\n",
      "    first director of the Paris Observatory, who discovered several of\n",
      "    Saturn's satellites and the major division in its rings. The Titan\n",
      "    atmospheric entry probe is named for the Dutch physicist Christiaan\n",
      "    Huygens (1629-1695), who discovered Titan and first described the true\n",
      "    nature of Saturn's rings.\n",
      "\n",
      "\t Key Scheduled Dates for the Cassini Mission (VVEJGA Trajectory)\n",
      "\t -------------------------------------------------------------\n",
      "\t   10/06/97 - Titan IV/Centaur Launch\n",
      "\t   04/21/98 - Venus 1 Gravity Assist\n",
      "\t   06/20/99 - Venus 2 Gravity Assist\n",
      "\t   08/16/99 - Earth Gravity Assist\n",
      "\t   12/30/00 - Jupiter Gravity Assist\n",
      "\t   06/25/04 - Saturn Arrival\n",
      "\t   01/09/05 - Titan Probe Release\n",
      "\t   01/30/05 - Titan Probe Entry\n",
      "\t   06/25/08 - End of Primary Mission\n",
      "\t    (Schedule last updated 7/22/92)\n",
      "\n",
      "\n",
      "    GALILEO - Jupiter orbiter and atmosphere probe, in transit. Has returned\n",
      "    the first resolved images of an asteroid, Gaspra, while in transit to\n",
      "    Jupiter. Efforts to unfurl the stuck High-Gain Antenna (HGA) have\n",
      "    essentially been abandoned. JPL has developed a backup plan using data\n",
      "    compression (JPEG-like for images, lossless compression for data from\n",
      "    the other instruments) which should allow the mission to achieve\n",
      "    approximately 70% of its original objectives.\n",
      "\n",
      "\t   Galileo Schedule\n",
      "\t   ----------------\n",
      "\t   10/18/89 - Launch from Space Shuttle\n",
      "\t   02/09/90 - Venus Flyby\n",
      "\t   10/**/90 - Venus Data Playback\n",
      "\t   12/08/90 - 1st Earth Flyby\n",
      "\t   05/01/91 - High Gain Antenna Unfurled\n",
      "\t   07/91 - 06/92 - 1st Asteroid Belt Passage\n",
      "\t   10/29/91 - Asteroid Gaspra Flyby\n",
      "\t   12/08/92 - 2nd Earth Flyby\n",
      "\t   05/93 - 11/93 - 2nd Asteroid Belt Passage\n",
      "\t   08/28/93 - Asteroid Ida Flyby\n",
      "\t   07/02/95 - Probe Separation\n",
      "\t   07/09/95 - Orbiter Deflection Maneuver\n",
      "\t   12/95 - 10/97 - Orbital Tour of Jovian Moons\n",
      "\t   12/07/95 - Jupiter/Io Encounter\n",
      "\t   07/18/96 - Ganymede\n",
      "\t   09/28/96 - Ganymede\n",
      "\t   12/12/96 - Callisto\n",
      "\t   01/23/97 - Europa\n",
      "\t   02/28/97 - Ganymede\n",
      "\t   04/22/97 - Europa\n",
      "\t   05/31/97 - Europa\n",
      "\t   10/05/97 - Jupiter Magnetotail Exploration\n",
      "\n",
      "\n",
      "    HITEN - Japanese (ISAS) lunar probe launched 1/24/90. Has made\n",
      "    multiple lunar flybys. Released Hagoromo, a smaller satellite,\n",
      "    into lunar orbit. This mission made Japan the third nation to\n",
      "    orbit a satellite around the Moon.\n",
      "\n",
      "\n",
      "    MAGELLAN - Venus radar mapping mission. Has mapped almost the entire\n",
      "    surface at high resolution. Currently (4/93) collecting a global gravity\n",
      "    map.\n",
      "\n",
      "\n",
      "    MARS OBSERVER - Mars orbiter including 1.5 m/pixel resolution camera.\n",
      "    Launched 9/25/92 on a Titan III/TOS booster. MO is currently (4/93) in\n",
      "    transit to Mars, arriving on 8/24/93. Operations will start 11/93 for\n",
      "    one martian year (687 days).\n",
      "\n",
      "\n",
      "    TOPEX/Poseidon - Joint US/French Earth observing satellite, launched\n",
      "    8/10/92 on an Ariane 4 booster. The primary objective of the\n",
      "    TOPEX/POSEIDON project is to make precise and accurate global\n",
      "    observations of the sea level for several years, substantially\n",
      "    increasing understanding of global ocean dynamics. The satellite also\n",
      "    will increase understanding of how heat is transported in the ocean.\n",
      "\n",
      "\n",
      "    ULYSSES- European Space Agency probe to study the Sun from an orbit over\n",
      "    its poles. Launched in late 1990, it carries particles-and-fields\n",
      "    experiments (such as magnetometer, ion and electron collectors for\n",
      "    various energy ranges, plasma wave radio receivers, etc.) but no camera.\n",
      "\n",
      "    Since no human-built rocket is hefty enough to send Ulysses far out of\n",
      "    the ecliptic plane, it went to Jupiter instead, and stole energy from\n",
      "    that planet by sliding over Jupiter's north pole in a gravity-assist\n",
      "    manuver in February 1992. This bent its path into a solar orbit tilted\n",
      "    about 85 degrees to the ecliptic. It will pass over the Sun's south pole\n",
      "    in the summer of 1993. Its aphelion is 5.2 AU, and, surprisingly, its\n",
      "    perihelion is about 1.5 AU-- that's right, a solar-studies spacecraft\n",
      "    that's always further from the Sun than the Earth is!\n",
      "\n",
      "    While in Jupiter's neigborhood, Ulysses studied the magnetic and\n",
      "    radiation environment. For a short summary of these results, see\n",
      "    *Science*, V. 257, p. 1487-1489 (11 September 1992). For gory technical\n",
      "    detail, see the many articles in the same issue.\n",
      "\n",
      "\n",
      "    OTHER SPACE SCIENCE MISSIONS (note: this is based on a posting by Ron\n",
      "    Baalke in 11/89, with ISAS/NASDA information contributed by Yoshiro\n",
      "    Yamada (yamada@yscvax.ysc.go.jp). I'm attempting to track changes based\n",
      "    on updated shuttle manifests; corrections and updates are welcome.\n",
      "\n",
      "    1993 Missions\n",
      "\to ALEXIS [spring, Pegasus]\n",
      "\t    ALEXIS (Array of Low-Energy X-ray Imaging Sensors) is to perform\n",
      "\t    a wide-field sky survey in the \"soft\" (low-energy) X-ray\n",
      "\t    spectrum. It will scan the entire sky every six months to search\n",
      "\t    for variations in soft-X-ray emission from sources such as white\n",
      "\t    dwarfs, cataclysmic variable stars and flare stars. It will also\n",
      "\t    search nearby space for such exotic objects as isolated neutron\n",
      "\t    stars and gamma-ray bursters. ALEXIS is a project of Los Alamos\n",
      "\t    National Laboratory and is primarily a technology development\n",
      "\t    mission that uses astrophysical sources to demonstrate the\n",
      "\t    technology. Contact project investigator Jeffrey J Bloch\n",
      "\t    (jjb@beta.lanl.gov) for more information.\n",
      "\n",
      "\to Wind [Aug, Delta II rocket]\n",
      "\t    Satellite to measure solar wind input to magnetosphere.\n",
      "\n",
      "\to Space Radar Lab [Sep, STS-60 SRL-01]\n",
      "\t    Gather radar images of Earth's surface.\n",
      "\n",
      "\to Total Ozone Mapping Spectrometer [Dec, Pegasus rocket]\n",
      "\t    Study of Stratospheric ozone.\n",
      "\n",
      "\to SFU (Space Flyer Unit) [ISAS]\n",
      "\t    Conducting space experiments and observations and this can be\n",
      "\t    recovered after it conducts the various scientific and\n",
      "\t    engineering experiments. SFU is to be launched by ISAS and\n",
      "\t    retrieved by the U.S. Space Shuttle on STS-68 in 1994.\n",
      "\n",
      "    1994\n",
      "\to Polar Auroral Plasma Physics [May, Delta II rocket]\n",
      "\t    June, measure solar wind and ions and gases surrounding the\n",
      "\t    Earth.\n",
      "\n",
      "\to IML-2 (STS) [NASDA, Jul 1994 IML-02]\n",
      "\t    International Microgravity Laboratory.\n",
      "\n",
      "\to ADEOS [NASDA]\n",
      "\t    Advanced Earth Observing Satellite.\n",
      "\n",
      "\to MUSES-B (Mu Space Engineering Satellite-B) [ISAS]\n",
      "\t    Conducting research on the precise mechanism of space structure\n",
      "\t    and in-space astronomical observations of electromagnetic waves.\n",
      "\n",
      "    1995\n",
      "\tLUNAR-A [ISAS]\n",
      "\t    Elucidating the crust structure and thermal construction of the\n",
      "\t    moon's interior.\n",
      "\n",
      "\n",
      "    Proposed Missions:\n",
      "\to Advanced X-ray Astronomy Facility (AXAF)\n",
      "\t    Possible launch from shuttle in 1995, AXAF is a space\n",
      "\t    observatory with a high resolution telescope. It would orbit for\n",
      "\t    15 years and study the mysteries and fate of the universe.\n",
      "\n",
      "\to Earth Observing System (EOS)\n",
      "\t    Possible launch in 1997, 1 of 6 US orbiting space platforms to\n",
      "\t    provide long-term data (15 years) of Earth systems science\n",
      "\t    including planetary evolution.\n",
      "\n",
      "\to Mercury Observer\n",
      "\t    Possible 1997 launch.\n",
      "\n",
      "\to Lunar Observer\n",
      "\t    Possible 1997 launch, would be sent into a long-term lunar\n",
      "\t    orbit. The Observer, from 60 miles above the moon's poles, would\n",
      "\t    survey characteristics to provide a global context for the\n",
      "\t    results from the Apollo program.\n",
      "\n",
      "\to Space Infrared Telescope Facility\n",
      "\t    Possible launch by shuttle in 1999, this is the 4th element of\n",
      "\t    the Great Observatories program. A free-flying observatory with\n",
      "\t    a lifetime of 5 to 10 years, it would observe new comets and\n",
      "\t    other primitive bodies in the outer solar system, study cosmic\n",
      "\t    birth formation of galaxies, stars and planets and distant\n",
      "\t    infrared-emitting galaxies\n",
      "\n",
      "\to Mars Rover Sample Return (MRSR)\n",
      "\t    Robotics rover would return samples of Mars' atmosphere and\n",
      "\t    surface to Earch for analysis. Possible launch dates: 1996 for\n",
      "\t    imaging orbiter, 2001 for rover.\n",
      "\n",
      "\to Fire and Ice\n",
      "\t    Possible launch in 2001, will use a gravity assist flyby of\n",
      "\t    Earth in 2003, and use a final gravity assist from Jupiter in\n",
      "\t    2005, where the probe will split into its Fire and Ice\n",
      "\t    components: The Fire probe will journey into the Sun, taking\n",
      "\t    measurements of our star's upper atmosphere until it is\n",
      "\t    vaporized by the intense heat. The Ice probe will head out\n",
      "\t    towards Pluto, reaching the tiny world for study by 2016.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(tm.recommend(text=rawtext, n=1)[0][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
